package org.ljy.springblog.service;

import org.apache.catalina.User;
import org.ljy.springblog.mapper.BlogInfoMapper;
import org.ljy.springblog.mapper.UserInfoMapper;
import org.ljy.springblog.model.BlogInfo;
import org.ljy.springblog.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    @Autowired
    private BlogInfoMapper blogInfoMapper;


    //1.根据用户名获取用户信息
    public UserInfo getUserInfoByName(String userName) {
        return userInfoMapper.selectByName(userName);
    }

    //2.根据用户id，查询用户信息
    public UserInfo getUserInfoById(int userId) {
        return userInfoMapper.selectById(userId);
    }

    //3.根据博客id，拿到作者信息
    public UserInfo getUserInfoByBlogId(Integer blogId) {
        //1.根据博客id，拿到作者id
        BlogInfo blogInfo = blogInfoMapper.selectBlogInfoById(blogId);
        Assert.notNull(blogInfo,"bloginfo is null");
        Integer userId = blogInfo.getUserId();
        //2.根据作者id，拿到作者信息
        return userInfoMapper.selectById(userId);
    }
}
